package com.pan.api.filter;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

public class ControllerFilterImpl implements ControllerFilter {
    @Override
    public Class filter(Class clazz) {
        for (Class c = clazz; c != Object.class; c = c.getSuperclass()) {
            if (clazz.getAnnotations().length == 0) continue;
            if (c.isAnnotationPresent(Controller.class) || c.isAnnotationPresent(RestController.class)) {
                return c;
            }
        }
        return null;
    }


//    public List<Class> filter(List<Class> classes) {
//        List<Class> resultList = new ArrayList<>();
//        pan: for (Class clazz: classes) {
//            qi:for (Class c = clazz; c != Object.class; c = c.getSuperclass()) {
//                if (clazz.getAnnotations().length == 0) continue qi;
//                if (c.isAnnotationPresent(Controller.class) || c.isAnnotationPresent(RestController.class)) {
//                    resultList.add(c);
//                    continue pan;
//                }
//            }
//        }
//        return resultList;
//    }
}
